package com.lyc.controller;

import com.lyc.pojo.Result;
import com.lyc.utils.AliOssutil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadContorller {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件存储到本地磁盘上
        String originalFilename = file.getOriginalFilename();
        //保证文件名唯一，防止文件名重复
        String FileName = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));

        String  url= AliOssutil.uploadFile(FileName,file.getInputStream());
        return Result.success(url);
    }

    @PostMapping("/register/avatar")
    public Result<String> RegisterUpload(MultipartFile file) throws Exception {
        //把文件存储到本地磁盘上
        String originalFilename = file.getOriginalFilename();
        //保证文件名唯一，防止文件名重复
        String FileName = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));

        String  url= AliOssutil.uploadFile(FileName,file.getInputStream());
        return Result.success(url);
    }


}
